#include "comm.h"

int main()
{
  int fd = open(FIFO_FILE, O_WRONLY);
  if(fd < 0)
  {
    perror("open error");
    return 1;
  }
  
  int infile = open("file.txt", O_RDONLY);
  char buf[64];
  while(1)
  {
    //dup2(infile, 0);//从文件中重定向到标准输入
    //ssize_t s = read(0, buf, sizeof(buf)-1);//从标准输入读
    //int s = read(0, buf, sizeof(buf)-1);//从标准输入读
    int s = read(infile, buf, sizeof(buf)-1);//从标准输入读 不加dup版本
    if(s == sizeof(buf)){
      write(fd, buf, s);//写到管道文件中，写s长度
    }
    else if(s < (int)sizeof(buf)){
      write(fd, buf ,s);//文件内容小于已定义buf长度
      printf("read end of file!\n");
      break;
    }
    else{
      break;
    }
  }
   close(fd);
   close(infile);
   return 0;
}
